package com.sskj.market.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.market.bean.CreateOrderBean;
import com.sskj.market.bean.DefaultAddressBean;
import com.sskj.market.ui.activity.SubmitOrderActivity;

/**
 * @author :budou
 * Package :com.sskj.market.presenter
 * Date :2019/7/25 14:31
 * Describe :提交订单presenter
 * Remark :
 */
public class SubmitOrderPresenter extends BasePresenter<SubmitOrderActivity> {

    //获取默认地址

    public void listDefaultAddress(SubmitOrderPresenter presenter) {
        httpService.getDefaultAddress()
                .tag(this)
                .execute(new JsonCallBack<DefaultAddressBean>(presenter, true) {
                    @Override
                    public void onSuccess(Response<DefaultAddressBean> response) {
                        mView.getDefaultAddressSuccess(response.body());
                    }

                    @Override
                    public void onError(Response<DefaultAddressBean> response) {
                        super.onError(response);
                        mView.getDefaultAddressFailed("--");
                    }
                });
    }


    /**
     * 生成订单
     */
    public void createOrder(String productId, String areaId, String num, String remarks, SubmitOrderPresenter presenter) {
        httpService.createOrder(productId, areaId, num, remarks)
                .execute(new JsonCallBack<CreateOrderBean>(presenter, true) {
                    @Override
                    public void onSuccess(Response<CreateOrderBean> response) {
                        CreateOrderBean createOrderBean = response.body();
                        ToastUtil.showShort(createOrderBean.getMsg());
                        mView.createOrderSuccess(response.body()
                        );
                    }

                });
    }


}
